package mysgoog.bot.algo;

import mysgoog.board.Board;
import mysgoog.gtp.Color;
import mysgoog.gtp.Vertex;

public class Wall {
	
	
	private static final int[] adjX= {0,0,1,-1};
	private static final int[] adjY= {1,-1,0,0};
		
	
	public static Vertex block(Board board,Color mycolor,int opp){
		Color oppcolor = mycolor.complement();
		int oppx = board.posX(opp);
		int oppy = board.posY(opp);
		
		for(int i=0;i<4;++i){
			int ex = oppx+adjX[i];
			int ey = oppy+adjY[i];
			int epos = board.makePos(ex,ey);
			int refpos = board.makePos(oppx-adjX[i],oppy-adjY[i]); 			
			
			if(board.inBoard(epos) && board.inBoard(refpos)&&
					board.getStone(epos)==Color.EMPTY && board.getStone(refpos)==oppcolor){
				for(Integer eAdj: board.getAdjacent(epos)){
					if(board.getStone(eAdj)==mycolor){
						return new Vertex(epos);
					}
				}				
			}			
		}
		return null;
	}
}
